from django.db import models
from utils.models import BaseModel
# Create your models here.

class ContentCategory(BaseModel):
    """内容分类"""
    name = models.CharField(max_length=10, unique=True, verbose_name="名称")
    key = models.CharField(max_length=10, unique=True, verbose_name="类别键名")
    class Meta:
        db_table = "tb_content_category"
        verbose_name = "广告内容分类"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name

class Content(BaseModel):
    """广告内容"""
    # 外键关联.models.CASCADE: 级联删除,models.PROTECT: 保护删除,不允许删除关联的对象
    category = models.ForeignKey(ContentCategory,on_delete=models.PROTECT,verbose_name="广告分类")
    title = models.CharField(max_length=100, verbose_name="标题")
    url = models.CharField(max_length=300, verbose_name="内容链接")
    image = models.ImageField(null=True, blank=True, verbose_name="图片")
    text = models.TextField(null=True, blank=True, verbose_name="内容")
    # 排序字段,默认值为0,值越小,排序越靠前
    sequence = models.IntegerField(default=0, verbose_name="排序")
    status = models.BooleanField(default=True, verbose_name="是否展示")

    class Meta:
        db_table = "tb_content"
        verbose_name = "广告内容"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.category.name + ": " + self.title
